﻿using BenCaoXuan.Infrastructure.Attr;
using BenCaoXuan.Infrastructure.Dto.PC;
using BenCaoXuan.Service.Interface.admin;
using BenCaoXuan.Service.Interface.PC;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Mysqlx.Crud;

namespace BenCaoXuan.Api.Admin.Controllers.pc
{
    [ApiGroup("PC(桌面端模块)")]
    public class MainController : PcController
    {
        private readonly I_Main_Service _i_Main_Service;
        private readonly I_PcLogin_Service _i_PcLogin_Service;
        private readonly IConfiguration _configuration;

        public MainController(I_Main_Service i_Main_Service, I_PcLogin_Service i_PcLogin_Service, IConfiguration configuration) : base(configuration, i_PcLogin_Service)
        {
            _i_Main_Service = i_Main_Service;
            _i_PcLogin_Service = i_PcLogin_Service;
            _configuration = configuration;
        }


        /// <summary>
        /// 获取所有房间
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Rooms()
        {
            var result = await _i_Main_Service.Get_Rooms();

            return Ok(result);
        }


        /// <summary>
        /// 获取空闲房间
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Leisure_Room()
        {
            var result = await _i_Main_Service.Get_Leisure_Room();

            return Ok(result);
        }


        /// <summary>
        /// 获取员工(前台)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Employees_Front()
        {
            var result = await _i_Main_Service.Get_Employees_Front();

            return Ok(result);
        }


        /// <summary>
        /// 获取空闲员工(理疗师)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Employees()
        {
            var result = await _i_Main_Service.Get_Employees();

            return Ok(result);
        }

        /// <summary>
        /// 预约已通知
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Appointment_Inform(string id)
        {
            var result = await _i_Main_Service.Appointment_Inform(id);

            return Ok(result);
        }

        

        /// <summary>
        /// 获取待安排的预约信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Plan_Appointment(int? page = 1, int? limit = 999, string? key = "")
        {
            var result = await _i_Main_Service.Get_Plan_Appointment(new Appointment_Dto
            {
                limit = limit ?? 999,
                page = page ?? 1,
                key = key ?? ""
            });

            return Ok(result);
        }

        /// <summary>
        /// 获取待支付的订单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Plan_Order(int? page = 1, int? limit = 999, string? key = "")
        {
            var result = await _i_Main_Service.Get_Plan_Order(new Orders_Dto 
            {
                limit = limit ?? 999,
                page = page ?? 1,
                key = key ?? ""
            });

            return Ok(result);
        }


        /// <summary>
        /// 获取所有支付方式
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Pay()
        {
            var result = await _i_Main_Service.Get_Pay();

            return Ok(result);
        }

        /// <summary>
        /// 修改预约状态
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Change_Appointment_Status(int? status, string? time, string id)
        {
            var result = await _i_Main_Service.Change_Appointment_Status(new Appointment_Dto
            {
                id = id,
                status = status,
                time = time,
            });

            return Ok(result);
        }

        /// <summary>
        /// 获取当天预约记录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Appointment(int? page = 1, int? limit = 3, string? key = "")
        {
            var result = await _i_Main_Service.Get_Appointment(new Appointment_Dto
            {
                limit = limit ?? 3,
                page = page ?? 1,
                key = key ?? ""
            });

            return Ok(result);
        }

        /// <summary>
        /// 获取当天的未拨打预约
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Inform_Appointment(int? page = 1, int? limit = 3, string? key = "")
        {
            var result = await _i_Main_Service.Get_Inform_Appointment(new Appointment_Dto
            {
                limit = limit ?? 3,
                page = page ?? 1,
                key = key ?? ""
            });

            return Ok(result);
        }


        /// <summary>
        /// 新增预约
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Appointment(Appointment_Dto dto)
        {
            var result = await _i_Main_Service.Add_Appointment(dto);

            return Ok(result);
        }



        /// <summary>
        /// 直接生成订单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Order(Orders_Dto dto)
        {
            var user = this.Get_PC_User();

            var result = await _i_Main_Service.Add_Order(user.id, dto);

            return Ok(result);
        }

        /// <summary>
        /// 预约安排成订单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Arrange_Add_Order(Orders_Dto dto)
        {
            var user = this.Get_PC_User();

            var result = await _i_Main_Service.Arrange_Add_Order(user.id, dto);

            return Ok(result);
        }


        /// <summary>
        /// 订单支付
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Order_Pay(Orders_Dto dto)
        {
            var result = await _i_Main_Service.Order_Pay(dto);

            return Ok(result);
        }

        /// <summary>
        /// 修改订单服务
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Amend_Order(Orders_Dto dto)
        {
            var result = await _i_Main_Service.Amend_Order(dto);

            return Ok(result);
        }



        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="name"></param>
        /// <param name="gender"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Add_Customs(string phone, string name, int gender)
        {
            var result = await _i_Main_Service.Add_Customs(new Customs_Dto
            {
                phone = phone,
                name = name,
                gender = gender
            });

            return Ok(result);
        }

        /// <summary>
        /// 确认订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Order_Ko(string id)
        {
            var result = await _i_Main_Service.Order_Ko(id);

            return Ok(result);
        }


    }
}

